package main

import (
	"fmt"

	"github.com/hyperledger/fabric-protos-go/peer"
	"github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/lifecycle"
)

func NewChaincodeInfo(ccPath, ccLabel string) *ChaincodeInfo {
	info := ChaincodeInfo{
		Path:     ccPath,
		Label:    ccLabel,
		Sequence: 1,
		Version:  "1.0",
	}
	info.Package()
	return &info
}

type ChaincodeInfo struct {
	Path      string
	Label     string
	PackageId string
	Version   string
	PkgBytes  []byte
	Sequence  int64
}

func (c *ChaincodeInfo) Package() {
	desc := &lifecycle.Descriptor{
		Path:  c.Path,
		Type:  peer.ChaincodeSpec_GOLANG,
		Label: c.Label,
	}
	ccPkg, err := lifecycle.NewCCPackage(desc)
	if err != nil {
		fmt.Println(err)
	}
	c.PkgBytes = ccPkg
	c.PackageId = lifecycle.ComputePackageID(c.Label, c.PkgBytes)
}
